﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OneMake.Model
{
    //聚划算活动效果
    public class report_jhs_activity
    {
        [MapToField(FieldName = "日期")]
        public DateTime stat_datetime { get; set; }

        [MapToField(FieldName = "活动类型")]
        public string activity_type { get; set; }

        [MapToField(FieldName = "人数")]
        public int person_num { get; set; }

        [MapToField(FieldName = "人数占比")]
        public double person_rate { get; set; }

        [MapToField(FieldName = "交易笔数")]
        public int order_num { get; set; }

        [MapToField(FieldName = "笔数占比")]
        public double order_rate { get; set; }

        [MapToField(FieldName = "交易金额")]
        public double amount { get; set; }

        [MapToField(FieldName = "金额占比")]
        public double amount_rate { get; set; }
    }

    partial class ReportHelper
    {
        public List<report_jhs_activity> get_report_jhs_activity(int shopId, DateTime day)
        {
            List<report_jhs_activity> reports = new List<report_jhs_activity>();
            var db = new PetaPoco.Database("mysql" + UserSession.Network);

            report_jhs_activity report1 = new report_jhs_activity();
            report_jhs_activity report2 = new report_jhs_activity();
            report_jhs_activity report3 = new report_jhs_activity();
            report_jhs_activity report4 = new report_jhs_activity();

            report1.stat_datetime = day.Date;
            report2.stat_datetime = day.Date;
            report3.stat_datetime = day.Date;
            report4.stat_datetime = day.Date;

            report1.activity_type = "仅参加聚划算活动";
            report2.activity_type = "仅参加店铺活动";
            report3.activity_type = "同时参加聚划算与店铺活动";
            report4.activity_type = "小计";

            report1.person_num = 1;
            report2.person_num = 1;
            report3.person_num = 1;
            report4.person_num = report1.person_num + report2.person_num + report3.person_num;

            report1.person_rate = Math.Round((double)report1.person_num / report4.person_num, 2);
            report2.person_rate = Math.Round((double)report2.person_num / report4.person_num, 2);
            report3.person_rate = Math.Round((double)report3.person_num / report4.person_num, 2);
            report4.person_rate = 1.0;

            report1.order_num = 1;
            report2.order_num = 1;
            report3.order_num = 1;
            report4.order_num = report1.order_num + report2.order_num + report3.order_num;

            report1.order_rate = Math.Round((double)report1.order_num / report4.order_num, 2);
            report2.order_rate = Math.Round((double)report2.order_num / report4.order_num, 2);
            report3.order_rate = Math.Round((double)report3.order_num / report4.order_num, 2);
            report4.order_rate = 1.0;

            report1.amount = 1;
            report2.amount = 1;
            report3.amount = 1;
            report4.amount = report1.amount + report2.amount + report3.amount;

            report1.amount_rate = Math.Round((double)report1.amount / report4.amount, 2);
            report2.amount_rate = Math.Round((double)report2.amount / report4.amount, 2);
            report3.amount_rate = Math.Round((double)report3.amount / report4.amount, 2);
            report4.amount_rate = 1.0;

            reports.Add(report1);
            reports.Add(report2);
            reports.Add(report3);
            reports.Add(report4);

            return reports;
        }

        public List<report_jhs_activity> get_report_jhs_activity(int shopId, DateTime beginTime, DateTime endTime)
        {
            System.Diagnostics.Debug.Assert(beginTime <= endTime);

            List<report_jhs_activity> reports = new List<report_jhs_activity>();
            DateTime tempTime = beginTime;
            do
            {
                reports.AddRange(get_report_jhs_activity(shopId, tempTime));
                tempTime = tempTime.AddDays(1);
            }
            while (tempTime <= endTime);

            return reports;
        }
    }
}
